package org.xlp.validate.code;

import org.xlp.expression.ExpressionComplexity;
import org.xlp.expression.ExpressionEvaluator;
import org.xlp.expression.RandomMathExpressionGenerator;

/**
 * Description: 简单加减法数学表达式图片验证码生成器
 * <br/>date: 2024/12/2 23:30
 *
 * @version 1.0
 * @author: xlp
 */
public class MathExpressionValidateCode extends AbstractValidateCode{
    public MathExpressionValidateCode() {
        super();
    }

    public MathExpressionValidateCode(int width, int height) {
        super(width, height);
    }

    public MathExpressionValidateCode(int width, int height, int lineCount) {
        super(width, height, lineCount);
    }

    @Override
    protected String randomCode() {
        String expression = RandomMathExpressionGenerator
                .builder()
                .depth(3)
                .addSpace(false)
                .complexity(ExpressionComplexity.INT_A_S)
                .max(9)
                .generateExpression();
        setCodeCount(expression.length());
        return expression;
    }

    @Override
    public String getCode() {
        String code = super.getCode();
        return new ExpressionEvaluator(code).toString();
    }
}
